﻿Public Class clsPoprawki

#Region "Attributes"

    Private mvarDaneTab As New DataTable

#End Region

#Region "Properties"

    Public Property DaneTab() As DataTable
        Get
            Return mvarDaneTab
        End Get
        Set(ByVal value As DataTable)
            mvarDaneTab = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()
        UtworzTabele()
    End Sub

    Private Sub UtworzTabele()

        With mvarDaneTab.Columns
            .Add("klient", GetType(String))
            .Add("schemat", GetType(Integer))
            .Add("termin", GetType(String))
            .Add("pozycja_zlecenia_id", GetType(Integer))
            .Add("pozycja_schematu_id", GetType(Integer))
        End With

    End Sub

    Public Sub SzukajDanychZlecenia(lvarDbHolder As clsDataBase, IdDrut As String)

        Dim lvarNewRow As DataRow

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_tracking", "cls_poprawki", 1, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_drut_id", IdDrut)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read

                    lvarNewRow = mvarDaneTab.NewRow()
                    With lvarNewRow
                        .Item("klient") = IIf(IsDBNull(lvarReader.Item("nazwa_skrocona")), Nothing, lvarReader.Item("nazwa_skrocona"))
                        .Item("schemat") = IIf(IsDBNull(lvarReader.Item("schemat_id")), Nothing, lvarReader.Item("schemat_id"))
                        .Item("termin") = IIf(IsDBNull(lvarReader.Item("termin")), Nothing, lvarReader.Item("termin"))
                        .Item("pozycja_zlecenia_id") = IIf(IsDBNull(lvarReader.Item("pozycje_zlecenia_id")), Nothing, lvarReader.Item("pozycje_zlecenia_id"))
                        .Item("pozycja_schematu_id") = IIf(IsDBNull(lvarReader.Item("pozycje_schematu_id")), Nothing, lvarReader.Item("pozycje_schematu_id"))
                    End With
                    mvarDaneTab.Rows.Add(lvarNewRow)
                End While
            End If
        End If

    End Sub


#End Region

End Class
